﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;

namespace HotelRegistrationSystem.DAL
{
    public class AddressDAL
    {
        public static Address GetAddress(int id)
        {
            using (HotelRegistrationSystemEntities db = new HotelRegistrationSystemEntities())
            {         
                return db.Addresses.Find(id);
            } 
        }

        public static List<Address> GetAddresses()
        {
            using (HotelRegistrationSystemEntities db = new HotelRegistrationSystemEntities())
            {
                return db.Addresses.ToList();
            }
        }

        public static List<Address> GetAddressByCities()
        {
            return GetAddresses().GroupBy(x => x.City).Select(y => y.FirstOrDefault()).ToList();
        }
    }
}